//
//  MYPictureSelectedCell.m
//  MYChatting
//
//  Created by mac on 16/8/31.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYPictureSelectedCell.h"
#import "Masonry.h"

@interface MYPictureSelectedCell ()

@property (nonatomic,weak) UIButton *addBtn;
@property (nonatomic,weak) UIButton *deleteBtn;

@end

@implementation MYPictureSelectedCell



- (void)setImage:(UIImage *)image{
    _image = image;
    
    
    [self.addBtn setImage:image forState:UIControlStateNormal];
    self.deleteBtn.hidden = image == nil;
    
}


- (void)addBtnDidClick{
#warning 判读是否有响应，一定是delegate来判断，不是self来判断
    if ([self.delegate respondsToSelector:@selector(userWillChosePictureWithCell:)]) {
        [self.delegate userWillChosePictureWithCell:self];
    }
    
}


- (void)deleteBtnDidClick{
    if ([self.delegate respondsToSelector:@selector(userWillDeletePictureWithCell:)]) {
        [self.delegate userWillDeletePictureWithCell:self];
    }
    
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUi];
    }
    return self;
}


- (void)setUpUi{
    UIButton *addBtn = [[UIButton alloc] init];
    addBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [addBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add"] forState:UIControlStateNormal];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateHighlighted];
    [self.contentView addSubview:addBtn];
    [addBtn sizeToFit];
    [addBtn addTarget:self action:@selector(addBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    self.addBtn = addBtn;
    
    UIButton *deleteBtn = [[UIButton alloc] init];
    [deleteBtn setBackgroundImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
    [self.contentView addSubview:deleteBtn];
    [deleteBtn sizeToFit];
    [deleteBtn addTarget:self action:@selector(deleteBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    self.deleteBtn = deleteBtn;
    
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addBtn.mas_top);
        make.right.equalTo(addBtn.mas_right);
    }];
}


@end
